#ifndef LIGHTPRESETMODEL_H
#define LIGHTPRESETMODEL_H

#include <QAbstractListModel>

class LightPresetData;
class LightPresetFactory;


class LightPresetModel : public QAbstractListModel
{
   Q_OBJECT
public:
   explicit LightPresetModel( int numberOfChannels, LightPresetFactory *presetFactory,
                              QObject *parent = 0);
   ~LightPresetModel();

public :
   int rowCount(const QModelIndex &parent = QModelIndex()) const;
   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
   QVariant headerData(int, Qt::Orientation, int ) const;
   bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );

   Qt::ItemFlags flags(const QModelIndex &index) const;

   void updatePreset(const QString &name, int fadeMs, const QList<double> &targetValues);
   void updatePreset(const LightPresetData &preset);
   void removePreset(const LightPresetData &preset);

   void renamePreset( const QString &oldName, const QString &newName );

   QModelIndex searchByName(const QString &targetName) const;

   virtual bool moveRows(const QModelIndex &, int sourceRow, int count,
                         const QModelIndex &, int destinationChild);

   int numberOfChannels() {
      return m_numberOfChannels;
   }

public slots:
      void removePreset(const QString &presetName);
      void createVoidPreset();

private:
   LightPresetFactory *m_presetFactory;
   QList<const LightPresetData *> m_presetDataStore;
   int m_numberOfChannels;

private:
   void assertValidPosition(int position) const;
   void moveRows(int sourceRow, int count, int destinationRow);
   QList<double> fillTargetValues(const QList<double> &targetValues);
};

#endif // LIGHTPRESETMODEL_H
